########################################################################
# Project setup
########################################################################
cmake_minimum_required(VERSION 2.8.9)
project(plutoble CXX C)
enable_testing()
# select build type to get optimization flags
if(NOT CMAKE_BUILD_TYPE)
   set(CMAKE_BUILD_TYPE "Release")
   message(STATUS "Build type not specified: defaulting to release.")
endif(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "")

########################################################################
# Find libiio
########################################################################
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR})
find_package(libiio 0.9 REQUIRED)

if (LIBIIO_FOUND)
    message(STATUS "LIBIIO_INCLUDE_DIRS: ${LIBIIO_INCLUDE_DIRS}")
    message(STATUS "LIBIIO_LIBRARIES: ${LIBIIO_LIBRARIES}")
    message(STATUS "LIBIIO_DEFINITIONS: ${LIBIIO_DEFINITIONS}")
endif()

include_directories(${LIBIIO_INCLUDE_DIRS})

#enable c++11 features
set(CMAKE_CXX_STANDARD 11)

########################################################################
# Find libad9361
########################################################################
find_package(libad9361)

if (LIBAD9361_FOUND)
    message(STATUS "LIBAD9361_INCLUDE_DIRS: ${LIBAD9361_INCLUDE_DIRS}")
    message(STATUS "LIBAD9361_LIBRARIES: ${LIBAD9361_LIBRARIES}")
    message(STATUS "LIBAD9361_DEFINITIONS: ${LIBAD9361_DEFINITIONS}")
    include_directories(${LIBAD9361_INCLUDE_DIRS})
    add_definitions(-DHAS_AD9361_IIO)
endif()

if (MSVC)
	include_directories(${CMAKE_CURRENT_SOURCE_DIR}/deps/wingetopt/src)
	set(GETOPT_C_FILE ${CMAKE_CURRENT_SOURCE_DIR}/deps/wingetopt/src/getopt.c)
endif ()

find_package (Threads)

add_executable(plutoble plutoble.cpp bledecoder.cpp packetsender.cpp ${GETOPT_C_FILE})
target_link_libraries(plutoble ${LIBIIO_LIBRARIES} ${LIBAD9361_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})

INSTALL(TARGETS plutoble DESTINATION bin)
